<template>
  <div class="app-container">
    <!--  查询表单  -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="订单编号：" prop="orderId">
        <el-input v-model="queryParams.orderId" placeholder="请输入订单编号" clearable/>
      </el-form-item>
      <el-form-item label="国内运单号：" prop="cnTrackingNo">
        <el-input v-model="queryParams.cnTrackingNo" placeholder="请输入运单号" clearable/>
      </el-form-item>
      <el-form-item label="是否已入库：" prop="isWarehouse">
        <el-select v-model="queryParams.isWarehouse" placeholder="请选择入库状态">
          <el-option v-for="(item,index) in warehouseStatusList" :key="index" :label="item.label"
                     :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="发货类型：" prop="deliveryType">
        <el-select v-model="queryParams.deliveryType" placeholder="请选择发货类型">
          <el-option v-for="(item,index) in dict.type.send_out_type" :key="index" :label="item.label"
                     :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="商品编码：" prop="skuCode">
        <el-input v-model="queryParams.skuCode" placeholder="请输入商品编码" clearable/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-button type="primary" size="mini" plain @click="isShowOrderLogClick">截单记录</el-button>
      <el-button type="primary" size="mini" plain @click="addLogOpenClick">添加日志</el-button>
      <el-button v-if="tabsValue=='105'" size="mini" type="primary" @click="isOpenOfflineLogisticsOrder = true">
        线下物流单号
      </el-button>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <!--  订单列表  -->
    <!--        <order-table :tabsList="tabsList" :tabsIndex="tabsValue" :isShowSelection="false"></order-table>-->
    <el-tabs v-model="tabsValue" type="border-card" @tab-click="tabsClick">
      <el-tab-pane v-for="(item,index) in tabsList" :key="index" :label="item.label" :name="item.name">
        <div slot="label" v-if="item.name=='501' || item.name=='113' ">
          <div v-if="item.name=='501'">
            截单订单
            <el-badge :value="orderNumData.cutOffNum" class="item"></el-badge>
          </div>
          <div v-if="item.name=='113'">
            异常订单
            <el-badge :value="orderNumData.errorNum" class="item"></el-badge>
          </div>
        </div>
        <el-table v-loading="loading" ref="multipleTable" :data="sellerOrderList" default-expand-all row-key="id"
                  :tree-props="{children: 'sellerChildOrderList'}" border @select-all="selectAllCheckbox"
                  @selection-change="handleSelectionChange" :row-class-name="tableRowClassName">
          <el-table-column label="基本信息" min-width="250" prop="orderId">
            <template slot-scope="scope">
              <div v-if="!scope.row.childOrderId">
                <div>
                  <span>买家姓名：</span>
                  <span>{{ scope.row.aeStoreOrderReceiptAddress.contactPerson }}</span>
                </div>
                <div>
                  <span>电话：</span>
                  <span>{{
                      scope.row.aeStoreOrderReceiptAddress.phoneCountry + scope.row.aeStoreOrderReceiptAddress.mobileNo
                    }}</span>
                </div>
                <div style="display: flex">
                  <span>国家：</span>
                  <span>
                    <dict-tag :options="dict.type.county_code"
                              :value="scope.row.aeStoreOrderReceiptAddress.country"></dict-tag>
                  </span>
                </div>
                <div>
                  <span>收货地址：</span>
                  <span>
                    {{ scope.row.aeStoreOrderReceiptAddress.detailAddress }},
                    {{ scope.row.aeStoreOrderReceiptAddress.city }},
                    {{ scope.row.aeStoreOrderReceiptAddress.province }},
                    {{ scope.row.aeStoreOrderReceiptAddress.country }},
                    {{ scope.row.aeStoreOrderReceiptAddress.zip }}
                  </span>
                </div>
              </div>
              <div v-else>
                <div class="text-danger" v-if="scope.row.isEvaluation == '1' ">
                  <el-button type="danger" plain size="mini">疑似刷单</el-button>
                </div>
                <div class="img-box">
                  <span>子订单号：</span>
                  <span>{{ scope.row.childOrderId }}</span>
                </div>
                <!--                <div class="img-box">-->
                <!--                  <span>采购凭证：</span>-->
                <!--                  <span :class="scope.row.isProof == '1'? 'text-green ':'text-danger' ">{{-->
                <!--                      scope.row.isProof == '1' ? '已上传' : '未上传'-->
                <!--                    }}</span>-->
                <!--                </div>-->
                <div class="img-box">
                  <span>商品主图：</span>
                  <imagePreview :src="scope.row.snapshotSmallPhotoPath" width="50px" height="50px"/>
                </div>
                <div @click="getOrderQuantityStatistics(scope.row)">
                  出单量统计：
                  <el-button type="text">查看</el-button>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="商品信息" min-width="300">
            <template slot-scope="scope">
              <div v-if="scope.row.childOrderId">
                <div>ProductID： {{ scope.row.productId }}</div>
                <div>产品ID：{{ scope.row.collectProductId }}</div>
                <div>
                  <span>商品编码：</span>
                  <span>{{ scope.row.skuCode }}</span>
                  <!--                  <el-button-->
                  <!--                    v-if="scope.row.erpInnerOrderStatus == 103 && scope.row.skuCode"-->
                  <!--                    style="margin-left: 8px;"-->
                  <!--                    type="primary"-->
                  <!--                    size="mini"-->
                  <!--                    @click="ProByBtn(scope.row.skuCode, scope.row.childOrderId)"-->
                  <!--                    :loading="proByLoading"-->
                  <!--                  >库存-->
                  <!--                  </el-button>-->
                </div>
                <div>
                  <el-tooltip effect="dark" :content="scope.row.productName" placement="top">
                    <el-button type="text">
                      <div class="hidden-box" @click="goPersonalProduct(scope.row)">
                        商品名称：{{ scope.row.productName }}
                      </div>
                    </el-button>
                  </el-tooltip>
                </div>
                <div>买家选择物流方式：{{ scope.row.logisticsType }}</div>
              </div>
              <div v-else>
                <div v-if="scope.row.leftEndGoodTime" style="color: #ff4949">
                  <span>剩余时间：</span>
                  <span>
                    <count-down :endTime="endTime(scope.row.leftEndGoodTime)" endText="已结束"/>
                  </span>
                </div>
                <div style="display: flex">
                  <span>订单状态：</span>
                  <span>
                    <dict-tag :options="dict.type.ae_order_status" :value="scope.row.orderStatus"></dict-tag>
                  </span>
                </div>
                <div>订单号：{{ scope.row.orderId }}</div>
                <div>店铺：{{ scope.row.sellerLoginId }}</div>
                <div>卖家全名：{{ scope.row.sellerSignerFullname }}</div>
                <div>
                  <span>所属公司：</span>
                  <el-button size="mini" type="text" @click="getErpAgentBranchInfo(scope.row)">查看所属公司</el-button>
                </div>
                <div class="flex">
                  <span class="text-danger">发货类型：</span>
                  <dict-tag :options="dict.type.send_out_type" :value="scope.row.deliveryType"></dict-tag>
                </div>
                <div>
                  <span class="text-danger">备注：</span>
                  <span>{{ scope.row.memo ? scope.row.memo : '暂无' }}</span>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="订单金额" prop="bizType" min-width="180">
            <template slot-scope="scope">
              <div v-if="scope.row.childOrderId">
                <div>
                  <span>采购成本：</span>
                  <span v-if="scope.row.orderData.payCurrencyCode == 'USD'">
                    {{ scope.row.skuPrice == null ? '未知' : countPrice(scope.row.skuPrice) + 'RMB' }}
                  </span>
                  <span v-else>{{
                      scope.row.skuPrice == null ? '未知' : countPrice(scope.row.skuPrice) + 'RMB'
                    }} </span>
                </div>
                <div v-if="scope.row.erpInnerOrderStatus == '103'">
                  <span>采购链接：</span>
                  <span v-if="scope.row.skuBuyLink">
                      <el-button type="text" size="mini"
                                 @click="openProcurementLinkModal(scope.row)">查看采购链接</el-button>
                  </span>
                  <span v-else>无</span>
                </div>
                <div>
                  <span>商品数量：</span>
                  <span>{{ scope.row.productCount }}</span>
                </div>
                <div>
                  <span>商品规格：</span>
                  <span>{{ scope.row.skuPropertyIds }}</span>
                </div>
                <div>
                  <span>入库委托单号：</span>
                  <span>{{ scope.row.inConsignNo }}</span>
                </div>
                <div class="flex">
                  <span>商品属性：</span>
                  <span :class="scope.row.productAttribute=='2'?'text-danger':''">
                  <dict-tag :options="dict.type.erp_product_attribute" :value="scope.row.productAttribute"></dict-tag>
                  </span>
                </div>

              </div>
              <div v-else>
                <div v-if="scope.row.payCurrencyCode == 'USD'">
                  <div>订单金额：{{ scope.row.payAmount }} RMB</div>
                  <div>联盟佣金：{{ scope.row.afflicateFeeRate }} RMB</div>
                  <div>交易佣金：{{ scope.row.escrowFeeRate }} RMB</div>
                  <div>预估利润：
                    {{
                      scope.row.estimatedProfit == null ? '未知' : scope.row.estimatedProfit + 'RMB'
                    }}
                  </div>
                </div>
                <div v-else>
                  <div>订单金额：{{ scope.row.payAmount }} RMB</div>
                  <div>联盟佣金：{{ scope.row.afflicateFeeRate }} RMB</div>
                  <div>交易佣金：{{ scope.row.escrowFeeRate }} RMB</div>
                  <div>预估利润：{{
                      scope.row.estimatedProfit == null ? '未知' : scope.row.estimatedProfit + 'RMB'
                    }}
                  </div>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="时间" prop="orderStatus" min-width="200">
            <template slot-scope="scope">
              <div v-if="scope.row.childOrderId">
                <div>
                  <span>创建时间：</span>
                  <span>{{ scope.row.orderData.gmtCreate }}</span>
                </div>
                <div>
                  <span>付款时间：</span>
                  <span>{{ scope.row.orderData.gmtPayTime }}</span>
                </div>
                <div>
                  <span>更新时间：</span>
                  <span>{{ scope.row.orderData.updateTime }}</span>
                </div>
                <div v-if="scope.row.erpInnerOrderStatus != '103'">
                  <span>国内运单号：</span>
                  <span class="changeHand text-blue" @click="getLogisticsIngo(scope.row)">{{
                      scope.row.trackingNo
                    }}</span>
                </div>
              </div>
              <div v-else>
                <div v-if="scope.row.erpInnerOrderStatus == '105'">
                  <div>
                    <span class="text-blue">入库状态：</span>
                    <span v-if="scope.row.isWarehouse == 1">已入库</span>
                    <span v-else-if="scope.row.isWarehouse == 2">仓储发货</span>
                    <span v-else>未入库</span>
                  </div>
                </div>
                <div v-if="scope.row.erpInnerOrderStatus == '106' || scope.row.erpInnerOrderStatus == '1061'">
                  <div>出库：{{ scope.row.consignmentNo == null ? '暂无' : scope.row.consignmentNo }}</div>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="120" align="center" fixed="right">
            <template slot-scope="scope">
              <div v-if="scope.row.childOrderId">
                <div v-if="tabsValue == 'all' ">
                  <el-button size="mini" type="text" @click="openVoucherModal(scope.row)">查看采购凭证</el-button>
                </div>
                <div v-if="tabsValue == 103">
                  <el-badge :is-dot="scope.row.isProof == '1'?true:false" class="mt20 mr10">
                    <el-button size="mini" type="text" @click="openVoucherModal(scope.row)">上传采购凭证</el-button>
                  </el-badge>
                  <el-button size="mini" type="text" @click="editDomesticWaybill(scope.row)">填写国内运单号</el-button>
                </div>
                <el-button size="mini" type="text" v-if="tabsValue == 105"
                           @click="editDomesticWaybill(scope.row)">修改国内运单号
                </el-button>
                <div v-if="scope.row.erpInnerOrderStatus == 601">
                  <el-button size="mini" type="text" @click="chooseOrder(scope.row,602)">同意仓储</el-button>
                  <el-button size="mini" type="text" @click="chooseOrder(scope.row,603)">拒绝仓储</el-button>
                </div>
                <!--                <el-button size="mini" type="text" @click="transferStorage(scope.row)">转仓储</el-button>-->
              </div>
              <div v-else>
                <el-button size="mini" type="text" @click="openOrderDetail(scope.row)">详情</el-button>
                <el-button size="mini" type="text" @click="getOrderLog(scope.row)">查看订单记录</el-button>
                <el-button size="mini" type="text" @click="openSetMarkModal(scope.row)">设置备注</el-button>
                <el-button v-if="item.name==1071" size="mini" type="text" @click="declarationShipment(scope.row)">
                  快速声明发货
                </el-button>
                <div v-if="tabsValue==103">
                  <el-button size="mini" type="text" @click="warehouseShipping(scope.row)">仓储发货</el-button>
                  <el-button size="mini" type="text" @click="openFreightTrialModal(scope.row)">查看物流方案</el-button>
                  <!--                  <el-button size="mini" type="text" @click="skuWarehouse(scope.row)">SKU入库</el-button>-->
                  <el-button size="mini" type="text" @click="openSendoutGoodsModal(scope.row,'0')">查看菜鸟物流方案
                  </el-button>
                </div>

                <div v-if="tabsValue == 103 || tabsValue == 105">
                  <el-button size="mini" type="text" @click="orderReject(scope.row)">问题件驳回</el-button>
                </div>
                <div v-if="tabsValue == 105">
                  <el-button size="mini" type="text" @click="openSendoutGoodsModal(scope.row,'1')">去发货</el-button>
                  <el-button size="mini" type="text" @click="openOfflineLogisticsOrder(scope.row,'0')">编写单号
                  </el-button>
                  <el-button size="mini" type="text" @click="openOfflineLogisticsOrder(scope.row,'1')">修改单号
                  </el-button>
                  <el-button size="mini" type="text" @click="syncOnlineLogisticsOrders(scope.row)">同步线上物流订单
                  </el-button>
                </div>
                <div v-if="scope.row.erpInnerOrderStatus == '1075'">
                  <el-button size="mini" type="text" @click="handleOrderShipped(scope.row)">订单已发货
                  </el-button>
                  <el-button size="mini" type="text" @click="openOfflineLogisticsOrder(scope.row,'1')">修改单号
                  </el-button>
                </div>
                <div v-if="scope.row.erpInnerOrderStatus == 501">
                  <el-button size="mini" type="text" @click="agreeCutOrder(scope.row)">同意截单</el-button>
                  <el-button size="mini" type="text" @click="orderRefuse(scope.row)">拒绝截单</el-button>
                </div>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
    </el-tabs>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>
    <!--  填写国内运单号弹窗  -->
    <writeDomesticWaybill v-if="isOpenDomesticWaybill" :childOrderId="childOrderId" :orderId="orderId"
                          :sendOutTypeList="dict.type.send_out_type"
                          @domesticWaybillSwitch="domesticWaybillSwitch"></writeDomesticWaybill>
    <!--  上传购买凭证  -->
    <el-dialog
      title="上传购买凭证"
      :visible.sync="isOpenUploadVocher"
      width="670px">
      <div class="edit-box">
        <el-form size="small" :model="purchaseVoucherInfo" :rules="purchaseVoucherInfoRules" ref="purchaseVoucherRef"
                 label-width="120px">
          <el-form-item label="购买凭证：" prop="proof">
            <div v-if="tabsValue=='all'">
              <image-preview :src="purchaseVoucherInfo.proof"></image-preview>
            </div>
            <div v-else>
              <image-upload v-model="purchaseVoucherInfo.proof" :is-show-tip="false" width="50px"
                            height="50px"/>
            </div>
          </el-form-item>
          <el-form-item label="采购价格：" prop="purchasePrice">
            <el-input :disabled="tabsValue=='all'" v-model="purchaseVoucherInfo.purchasePrice"
                      placeholder="请输入采购价格"/>
          </el-form-item>
          <el-form-item label="发货类型：" prop="type">
            <el-select :disabled="tabsValue=='all'" v-model="purchaseVoucherInfo.type" placeholder="请选择发货类型"
                       size="small">
              <el-option v-for="(item,index) in dict.type.send_out_type" :key="index" :label="item.label"
                         :value="item.value"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isOpenUploadVocher = false">取 消</el-button>
        <el-button v-if="tabsValue !='all' " type="primary" @click="confirmVocher()">确 定</el-button>
      </span>
    </el-dialog>
    <!--  订单详情  -->
    <order-detail v-if="isOpenOrderDetail" :id="orderId" @orderDetailSwitch="orderDetailSwitch"></order-detail>
    <!--  运费试算弹窗  -->
    <FreightTrial v-if="isOpenFreightTrial" :orderId="orderId" :logisticsInfo="logisticsInfo"
                  :isSendOutGoods="isSendOutGoods" :isCaiNiao="isCaiNiao"
                  @logisticsSwitch="logisticsSwitch"></FreightTrial>
    <!-- 订单日志 -->
    <order-log v-if="isOpenOrderLog" :orderId="orderId" @closeOrderLogModal="closeOrderLogModal"></order-log>
    <!--  修改采购链接弹窗  -->
    <changeProcurementLink v-if="isOpenProcurementLink" :skuCode="skuCode"
                           @procurementLinkSwitch="procurementLinkSwitch"></changeProcurementLink>
    <!--  截单转仓储弹窗  -->
    <transferWarehouse v-if="isOpenTransferWarehouse" :childOrderId="childOrderId" :orderId="orderId"
                       :sendGoodsInfoList="sendGoodsInfoList"
                       @closeTransferWarehouse="closeTransferWarehouse"></transferWarehouse>
    <!-- 转仓储选择仓库 -->
    <el-dialog
      title="转仓储选择仓库"
      :visible.sync="isTransfer"
      width="670px">
      <div class="edit-box">
        <el-form size="small" :model="transferForm" :rules="transferRules" ref="transferRef"
                 label-width="120px">
          <el-form-item label="选择仓库：" prop="warehouseId">
            <el-select v-model="transferForm.warehouseId" placeholder="请选择仓库" size="small">
              <el-option
                v-for="dict in warehouseList"
                :key="dict.warehouseName"
                :label="dict.warehouseName"
                :value="dict.warehouseId"
              />
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isTransfer = false">取 消</el-button>
        <el-button type="primary" @click="confirmTransfer()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 库存 -->
    <el-dialog
      title="库存列表"
      :visible.sync="isProBy"
      width="1000px">
      <div class="edit-box">
        <el-table :data="proByList" @selection-change="proBySelectionChange">
          <el-table-column type="selection" width="55" align="center"/>
          <el-table-column label="商品编码" align="center" prop="skuCode"/>
          <el-table-column label="sku名称" align="center" prop="skuName"/>
          <el-table-column label="sku图片" align="center" prop="skuImg">
            <template slot-scope="scope">
              <image-preview :src="scope.row.skuImg" width="60px" height="60px"></image-preview>
            </template>
          </el-table-column>
          <el-table-column label="仓储状态" align="center" prop="status">
            <template slot-scope="scope">
              {{
                scope.row.status == '0' ? '在途' : scope.row.status == '1' ? '入库' : scope.row.status == '2' ? '出库' :
                  ''
              }}
            </template>
          </el-table-column>
          <el-table-column label="仓储数量" align="center" prop="number"/>
          <el-table-column label="国内运单号" align="center" prop="cnTrackingNo"/>
          <el-table-column label="4px出库委托号" align="center" prop="consignmentNo"/>
          <el-table-column label="所在仓库名称" align="center" prop="warehouseName"/>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isProBy = false">取 消</el-button>
        <el-button :disabled="proMultiple || proLoading" :loading="proLoading" type="primary" @click="confirmProBy()">仓储发货</el-button>
      </span>
    </el-dialog>
    <!-- 截单记录 -->
    <el-dialog
      title="截单记录"
      :visible.sync="isShowOrderLog"
      width="70%">
      <div class="orderLog-box">
        <el-form :model="orderLogParams" ref="orderLogForm" size="small" :inline="true" v-show="showSearch"
                 label-width="100px">
          <el-form-item label="订单编号：" prop="orderId">
            <el-input v-model="orderLogParams.orderId" placeholder="请输入订单编号" clearable/>
          </el-form-item>
          <el-form-item label="店铺名称：" prop="storeName">
            <el-input v-model="orderLogParams.storeName" placeholder="请输入订单编号" clearable/>
          </el-form-item>
          <el-form-item label="状态：" prop="type">
            <el-select v-model="orderLogParams.type" placeholder="请选择">
              <el-option
                v-for="(item,index) in typeList"
                :key="index"
                :label="item.label"
                :value="item.value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleOrderLog">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetOrderLog">重置</el-button>
          </el-form-item>
        </el-form>

        <el-table :data="orderLogList" align="center" v-loading="orderLoading" style="width: 100%" border>
          <el-table-column prop="orderId" align="center" label="订单编号"></el-table-column>
          <el-table-column prop="storeName" align="center" label="店铺名称"></el-table-column>
          <el-table-column prop="erpAccount" align="center" label="ERP账号"></el-table-column>
          <el-table-column prop="statusIntro" align="center" label="日志说明"></el-table-column>
          <el-table-column prop="type" label="日志类型" align="center">
            <template slot-scope="scope">
              <span>{{
                  scope.row.type == 501 ? '截单申请' : scope.row.type == 502 ? '截单申请不通过' : '截单申请通过，已退款'
                }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="remark" label="备注" align="center"></el-table-column>
        </el-table>

        <pagination
          v-show="orderTotal>0"
          :total="orderTotal"
          :page.sync="orderLogParams.pageNum"
          :limit.sync="orderLogParams.pageSize"
          :pageSizes="[10, 20, 40]"
          @pagination="getOrderLogList"
        />
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isShowOrderLog = false">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 添加日志 -->
    <el-dialog title="添加日志" :visible.sync="addLogOpen" width="500px" append-to-body>
      <el-form ref="addLogform" :model="addLogform" :rules="addLogRules" label-width="180px">
        <el-form-item label="订单编号" prop="orderId">
          <el-input v-model="addLogform.orderId" placeholder="请输入订单编号"/>
        </el-form-item>
        <el-form-item label="日志类型" prop="orderProcessFlag">
          <el-input v-model="addLogform.orderProcessFlag" placeholder="请输入日志类型"/>
        </el-form-item>
        <el-form-item label="Erp内部流程代码标识" prop="previousOrderProcess">
          <el-select v-model="addLogform.previousOrderProcess" placeholder="请选择">
            <el-option
              v-for="dict in dict.type.erp_order_process_flag"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="ERP内部订单流转状态" prop="previousStatus">
          <el-select v-model="addLogform.previousStatus" placeholder="请选择">
            <el-option
              v-for="dict in dict.type.erp_inner_order_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="addLogform.remark" placeholder="请输入备注"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="addLogLoading" type="primary" @click="addLogConfirm">确 定</el-button>
        <el-button @click="addLogOpen = false">取 消</el-button>
      </div>
    </el-dialog>
    <!--  物流方案  -->
    <ReportInfo v-if="isOpenLogisticsModal" :logisticsInfo="logisticsFormInfo" :programmeForm="programmeForm"
                @reportInfoSwitch="reportInfoSwitch"/>
    <!--  物流信息  -->
    <notStockLogisticsInfo v-if="isOpenNotStockModal" :trackingNo="trackingNo"
                           @close="closeNotStack"></notStockLogisticsInfo>
    <!--  线下物流单号  -->
    <offlineLogisticsOrder v-if="isOpenOfflineLogisticsOrder" :storeId="storeId" :orderId="orderId"
                           :offlineLogisticsType="offlineLogisticsType" :storeList="storeList"
                           @close="closeOfflineLogisticsOrder"/>
  </div>
</template>

<script>
import notStockLogisticsInfo from "@/views/order/components/notStockLogisticsInfo.vue";
import offlineLogisticsOrder from "@/views/order/components/offlineLogisticsOrder.vue";
import {
  alterInnerStatus, sendOutOrderToFPX
} from '@/api/order/orderApi'
import {
  oldOrderSkuWarehousing,
  reviewFailed,
  querySendGoodsInfo,
  getLpCode,
  cutOrderSuccess,
  cutOrderFail,
  uploadProof,
  getWarehouseProBySkuCode,
  warehouseProReplenish,
  isInBound,
  listSellerOrder,
  querySendGoodsInfoList,
  cutOrderGoods,
  getErpAgentBranchInfo,
  WarehouseProBySkuCode,
  ChooseWarehouseShipment,
  createOrderLog,
  getRejectAndCutOffRecord,
  redReminderForCutOffOrder,
  setOrderMemo,
  synchronizationWarehouseOrder,
  declareProductInfo,
  getOrderCountByCode
} from "@/api/order/purchaser"
import {
  addWarehousInfo,
  warehouseList
} from "@/api/warehouse/warehouse";
import {formatDate} from "@/utils"
import service from "@/utils/request";
import Dict from "@/views/system/dict/index.vue";
import orderDetail from '@/views/components/order/order-detail.vue'
import FreightTrial from "@/views/purchase/components/FreightTrial.vue";
import countDown from '@/views/components/countDown/index.vue';
import ReportInfo from "@/views/purchase/components/ReportInfo.vue";
import changeProcurementLink from "@/views/order/purchaser/change-procurement-link.vue";
import writeDomesticWaybill from "@/views/order/purchaser/write-domestic-waybill.vue";
import transferWarehouse from "@/views/order/purchaser/transfer-warehouse.vue";
import {sellerShipmentForCaiNiao} from "@/api/order/packGroup";
import orderLog from "@/views/order/components/orderLog.vue";
import {queryUserShopList} from "@/api/shop";

export default {
  name: 'Order-list-purchaser',
  components: {
    Dict,
    orderDetail,
    FreightTrial,
    countDown,
    ReportInfo,
    changeProcurementLink,
    writeDomesticWaybill,
    transferWarehouse,
    orderLog,
    notStockLogisticsInfo,
    offlineLogisticsOrder
  },
  dicts: ['send_out_type', 'erp_inner_order_status', 'ae_order_type', 'ae_order_status', 'shipments_solution_type', 'county_code', 'ae_order_status', 'erp_logistics_type', 'erp_order_process_flag', 'erp_inner_order_status', 'erp_product_attribute'],
  data() {
    return {
      purchaseVoucherInfo: {},//购买凭证信息
      purchaseVoucherInfoRules: {
        proof: [{required: true, message: '请上传购买凭证', trigger: 'change'}],
        purchasePrice: [{required: true, message: '采购价格不能为空', trigger: 'blur'}],
        type: [{required: true, message: '请选择发货类型', trigger: 'change'}],
      },
      checkValue: false,
      onlineLogisticsList: [],//线上发货物流列表
      isOpenOnlineShipment: false,//是否打开线上发货物流信息
      isEditOrderSku: false,//是否编辑商品sku信息
      sendoutGoodsInfo: {},//线下发货信息填写
      logisticsInfo: {},//发货信息试算
      logisticsFormInfo: {},//同步物流表单信息
      logisticsRules: { //发货信息表单验证
        categoryCnDesc: [
          {required: true, message: '申报中文名称不能为空', trigger: 'blur'},
          {min: 0, max: 20, message: '长度在 0 到 20 个字符', trigger: 'blur'}
        ],
        categoryEnDesc: [
          {required: true, message: '申报英文名称不能为空', trigger: 'blur'},
          {min: 0, max: 60, message: '长度在 0 到 60 个字符', trigger: 'blur'}
        ],
        productDeclareAmount: [
          {required: true, message: '产品申报金额不能为空', trigger: 'blur'},
          {
            pattern: /^((0\.\d?[1-9])|(0\.[1-9]0)|([1-9]\d{0,3}(\.\d{1,2})?)|(10000(\.0{1,2})?))$/,
            message: '0.01-10000.00之间',
            trigger: 'blur'
          }
        ]
      },
      isOpenDomesticWaybill: false,// 是否打开填写国内运单号弹窗
      isOpenTransferWarehouse: false,//是否打开截单转仓储弹窗
      sendGoodsInfoList: [],//填写国内运单号信息
      buttonLoading: false,
      arrivalTime: "",// 预计到货时间
      orderId: '',
      storeId: "",
      childOrderId: "",//子订单id
      loading: false, // 遮罩层
      chooseOrderList: [], // 选中数组
      single: true, // 非单个禁用
      multiple: true, // 非多个禁用
      showSearch: true, // 显示搜索条件
      total: 0, // 总条数
      sellerOrderList: [], // 卖家订单表格数据
      warehouseStatusList: [{
        label: "是",
        value: 2
      }, {
        label: "否",
        value: 1
      }, {
        label: '仓储发货',
        value: 3
      }],
      title: '订单详情', // 弹出层标题
      isOpenOrderDetail: false, // 是否打开订单详情弹窗
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderId: undefined,
        bizType: undefined,
        gmtCreate: undefined,
        gmtPayTime: undefined,
        orderStatus: undefined,
        cnTrackingNo: undefined,//国内订单号
        isWarehouse: undefined,//是否已入库
        statusList: "103",
        orderProcessFlag: undefined,
        type: '1',
        deliveryType: '',//发货类型
      }, // 查询参数
      orderDetailForm: {}, // 订单详情
      form: '',
      tabsValue: '103',
      tabsList: [
        {
          name: '103',
          label: '待采购'
        }, {
          name: '105',
          label: '已采购'
        }, {
          name: '1061',
          label: '待同步国际运单'
        }, {
          name: '1071',
          label: '待发货'
        }, {
          name: '106',
          label: '待出库'
        }, {
          name: '501',
          label: '截单订单'
        }, {
          name: '701',
          label: '问题件'
        }, {
          name: '114',
          label: '已完成'
        }, {
          name: '113',
          label: '异常订单'
        }, {
          name: '1075',
          label: '燕文订单'
        }, {
          name: 'all',
          label: '全部'
        }],
      orderStatusData: {
        104: '采购',
        701: '驳回',
        502: '同意截单',
        503: '拒绝截单',
        // 106: '同步国内运单',
      }, //订单修改状态
      isOpenUploadVocher: false,//是否打开上传凭证模态框
      isChooseOrder: false,//是否选择订单
      isShowOrderLog: false,// 是否显示截单日志
      orderLogList: [],//截单日志列表
      isOpenLogisticsModal: false,//是否打开物流弹窗
      logisticsList: [],//物流方案列表
      logisticsProductCode: "",//线下物流id
      exchangeRate: 0,//美元人民币汇率
      isOperate: true, // 选择物流弹框是否显示操作栏
      isSelect: false, // 修改信息弹框
      proButtonLoading: false,// 提交按钮loading
      isOpenFreightTrial: false,//是否打开物流方案弹窗
      isSendOutGoods: false,//是否是去发货操作
      isCaiNiao: false,//是否是查看菜鸟物流方案
      isOpenProcurementLink: false,//是否打开修改采购链接弹窗
      skuCode: "",//子订单的规格Id
      isTransfer: false,
      transferForm: {},
      transferRules: {
        warehouseId: [{required: true, message: '请选择仓库', trigger: 'change'}]
      },
      warehouseList: [], // 仓库列表
      isProBy: false,
      proByLoading: false,
      proLoading: false,
      proByList: [],
      proIds: [],
      // 非单个禁用
      proSingle: true,
      // 非多个禁用
      proMultiple: true,
      proByParams: {
        warehouseProId: '',
        childOrderId: ''
      },
      orderLoading: false, // 截单日志loading
      orderTotal: 0,
      orderLogParams: {
        pageNum: 1,
        pageSize: 10,
        orderId: '',
        storeName: '',
        type: ''
      },
      addLogOpen: false, // 添加日志
      addLogform: {
        orderId: '',
        orderProcessFlag: '',
        remark: '',
        previousOrderProcess: '',
        previousStatus: ''
      },
      addLogRules: {
        orderId: [{required: true, message: '订单编号不能为空', trigger: 'blur'}],
        orderProcessFlag: [{required: true, message: '日志类型不能为空', trigger: 'blur'}],
        previousOrderProcess: [{required: true, message: '请选择Erp内部流程代码标识', trigger: 'change'}],
        previousStatus: [{required: true, message: '请选择ERP内部订单流转状态', trigger: 'change'}]
      },
      addLogLoading: false,
      typeList: [
        {
          label: '截单申请',
          value: '501'
        },
        {
          label: '截单申请不通过',
          value: '502'
        },
        {
          label: '截单申请通过，已退款',
          value: '503'
        }
      ],
      isOpenOrderLog: false,//是否显示订单日志
      orderNumData: "",//订单角标数量
      programmeForm: [],
      isOpenNotStockModal: false,//是否打开未入库物流信息弹窗
      trackingNo: "",//运单号
      isOpenOfflineLogisticsOrder: false,//是否打开线下物流单号弹窗
      offlineLogisticsType: "",//0：编写，1：修改
      storeList: [],//店铺列表
    }
  },
  computed: {
    endTime() {
      return time => {
        return new Date(time).getTime() / 1000 + ' '
      }
    }
  },
  created() {
    this.userInfo = this.$store.state.user.urserInfo;
    this.getList();
    this.getStoreList()
    this.getCutOffNum()
    // this.getSendoutLogistics();
    // this.getWarehouseList();
  },
  methods: {
    // 订单已发货
    handleOrderShipped(row) {
      this.$confirm('是否修改该订单为已发货状态？', '提示').then(() => {
        let data = {
          orderId: row.orderId,
          type: "1"
        }
        sendOutOrderToFPX(data).then(res => {
          this.$message.success(res.msg)
          this.getList()
        })
      })
    },
    // 获取店铺列表
    getStoreList() {
      queryUserShopList().then(res => {
        this.storeList = res.data
      })
    },
    // 打开填写线下物流单号弹窗
    openOfflineLogisticsOrder(row, type) {
      this.storeId = row.storeId
      this.orderId = row.orderId
      this.offlineLogisticsType = type
      this.isOpenOfflineLogisticsOrder = true
    },
    // 打开获取物流信息弹窗
    getLogisticsIngo(row) {
      this.trackingNo = row.trackingNo
      this.isOpenNotStockModal = true
    },
    // 关闭线下物流单号弹窗
    closeOfflineLogisticsOrder(e) {
      this.isOpenOfflineLogisticsOrder = false
      if (e == 'isRef') {
        this.getList()
      }
    },
    // 关闭未入库物流信息弹窗
    closeNotStack() {
      this.isOpenNotStockModal = false
    },
    // 获取出单量统计
    getOrderQuantityStatistics(row) {
      getOrderCountByCode({skuCode: row.skuCode}).then(res => {
        let data = res.data
        if (data) {
          let message = `<div>` + '近三天：' + data.threeDay + `</div>` + `<div>` + '近七天：' + data.sevenDay + `</div>` + `<div>` + '近一月：' + data.oneMonth + `</div>` + `<div>` + '纠纷率：' + data.violationRate + `</div>`;
          // for (let i = 0; i < data.length; i++) {
          //   message += `<div>` + list[i].branch + '——' + list[i].agent + '——' + list[i].userInfo + `</div>`
          // }
          this.$confirm(message, 'SKU出单量统计', {
            dangerouslyUseHTMLString: true,
          }).then(() => {

          })
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    // 获取截单订单数量
    getCutOffNum() {
      // this.queryParams.statusList = undefined
      redReminderForCutOffOrder().then(response => {
        this.orderNumData = response.data
      })
    },
    // 添加日志确认
    addLogConfirm() {
      this.$refs["addLogform"].validate(valid => {
        if (valid) {
          this.addLogLoading = true;
          createOrderLog(this.addLogform).then(response => {
            this.$modal.msgSuccess("新增成功");
            this.addLogOpen = false;
          }).finally(() => {
            this.addLogLoading = false;
          });
        }
      });
    },
    // 添加日志
    addLogOpenClick() {
      this.addLogOpen = true;
    },
    // 截单日志
    isShowOrderLogClick() {
      this.isShowOrderLog = true;
      this.getOrderLogList();
    },
    // 截单搜索
    handleOrderLog() {
      this.orderLogParams.pageNum = 1
      this.getOrderLogList();
    },
    // 获取日志列表
    getOrderLogList() {
      this.orderLoading = true;
      getRejectAndCutOffRecord(this.orderLogParams).then(res => {
        this.orderLoading = false;
        this.orderLogList = res.rows;
        this.orderTotal = res.total;
      })
    },
    // 库存
    ProByBtn(skuCode, childOrderId) {
      this.proByParams.childOrderId = childOrderId;
      this.proByLoading = true;
      WarehouseProBySkuCode({skuCode: skuCode}).then(res => {
        this.proByList = res.data;
        this.isProBy = true;
        this.proByLoading = false;
      }).catch(() => {
        this.proByLoading = false;
      })
    },
    // 库存确定
    confirmProBy() {
      this.proByParams.warehouseProId = this.proIds.join(',');
      this.proLoading = true;
      ChooseWarehouseShipment(this.proByParams).then(res => {
        this.proLoading = false;
        this.isProBy = false;
        this.$message.success(res.msg);
        this.getList();
      }).catch(() => {
        this.proLoading = false;
      })
    },
    proBySelectionChange(selection) {
      this.proIds = selection.map(item => item.id)
      this.proSingle = selection.length !== 1
      this.proMultiple = !selection.length
    },
    // 获取仓库列表
    getWarehouseList() {
      warehouseList().then(response => {
        this.warehouseList = response.data;
      });
    },
    // 获取订单店铺层级关系
    getErpAgentBranchInfo(row) {
      getErpAgentBranchInfo({sellerLoginId: row.sellerLoginId}).then(res => {
        let list = res.data;
        if (list) {
          let message = "";
          for (let i = 0; i < list.length; i++) {
            message += `<div>` + list[i].branch + '——' + list[i].agent + '——' + list[i].userInfo + `</div>`
          }
          this.$confirm(message, '所属公司', {
            dangerouslyUseHTMLString: true,
          }).then(() => {

          })
        } else {
          this.$message.error(res.msg)
        }

      })
    },
    service,
    onlineLogisticsSwitch(e) {
      this.isEditOrderSku = e
    },
    // 获取物流列表
    getSendoutLogistics() {
      getLpCode().then(res => {
        this.logisticsList = res.data
      })
    },
    // 确定上传凭证
    confirmVocher() {
      this.$refs['purchaseVoucherRef'].validate((valid) => {
        if (valid) {
          this.purchaseVoucherInfo.orderId = this.orderId
          this.purchaseVoucherInfo.childOrderId = this.childOrderId
          uploadProof(this.purchaseVoucherInfo).then(res => {
            this.$message.success(res.msg)
            this.isOpenUploadVocher = false
          })
        }
      })
    },
    // 打开上传凭证弹窗
    openVoucherModal(row) {
      this.orderId = row.orderId
      this.childOrderId = row.childOrderId
      this.reset()
      this.getSendGoodsInfo()
    },
    // 重置
    reset() {
      this.purchaseVoucherInfo = {
        type: undefined,
        proof: undefined,
        purchasePrice: undefined
      }
      // this.resetForm("purchaseVoucherRef");

    },
    // 打开设置备注弹窗
    openSetMarkModal(row) {
      let inputValue = row.memo ? row.memo : ''
      this.$prompt('请输入备注', '提示', {
        // inputPattern: /^.+$/,
        // inputErrorMessage: '请输入备注内容',
        inputValue: inputValue
      }).then((value) => {
        if (value) {
          // this.$confirm('是否确定设定该订单备注？', '提示').then(() => {
          let data = {
            orderId: row.orderId,
            memo: value.value
          }
          setOrderMemo(data).then(res => {
            this.$message.success(res.msg)
            this.getList()
          })
          // })
        }
      })
    },
    // 同步线上物流订单
    syncOnlineLogisticsOrders(row) {
      declareProductInfo({orderId: row.orderId}).then(res => {
        this.programmeForm = res.data;
        this.logisticsFormInfo = {
          orderId: row.orderId,
          sellerLoginId: row.sellerLoginId,
        }
        this.isOpenLogisticsModal = true
      })
    },
    // 关闭物流填报信息弹窗
    reportInfoSwitch() {
      this.isOpenLogisticsModal = false
    },
    // 打开查看物流方案弹窗
    openFreightTrialModal(row) {
      this.logisticsInfo = {//线上发货物流信息置为空
        orderId: row.orderId,
        sellerLoginId: row.sellerLoginId,
        country: row.aeStoreOrderReceiptAddress.country,
        logisticsServiceCode: row.sellerChildOrderList[0].logisticsType,
        zipCode: row.aeStoreOrderReceiptAddress.zip
      }
      this.isSendOutGoods = false
      this.isOpenFreightTrial = true
    },
    // 去发货
    openSendoutGoodsModal(row, type) {
      this.logisticsInfo = {
        orderId: row.orderId,
        sellerLoginId: row.sellerLoginId,
      }
      // type 0,菜鸟，1 去发货
      if (type == '0') {
        this.isOpenFreightTrial = true
        this.isSendOutGoods = true
        this.isCaiNiao = true
      } else {
        // isInBound({orderId: row.orderId}).then(response => {
        //   if (response.data) {
        this.isOpenFreightTrial = true
        this.isSendOutGoods = true
        this.isCaiNiao = false
        //   } else {
        //     this.$message.error(response.msg)
        //   }
        // })
      }

    },
    // 获取已上传的凭证和运单号信息
    getSendGoodsInfo() {
      let data = {
        childOrderId: this.childOrderId
      }
      querySendGoodsInfo(data).then(res => {
        let data = res.data
        if (data) {
          this.purchaseVoucherInfo = data
          this.purchaseVoucherInfo.type = data.type.toString()
          if (this.purchaseVoucherInfo.type == 0) {
            this.purchaseVoucherInfo.type = undefined
          }
          this.isOpenUploadVocher = true
        }
      })
    },
    // 关闭运费试算弹窗
    logisticsSwitch(e) {
      this.isOpenFreightTrial = false
      if (e == '1') {
        this.getList()
      }
    },
    // 关闭查看采购链接弹窗
    procurementLinkSwitch(e) {
      this.isOpenProcurementLink = e
      // this.getList()
    },
    // 填写国际运单号
    editDomesticWaybill(row) {
      this.orderId = row.orderId
      this.childOrderId = row.childOrderId
      this.isOpenDomesticWaybill = true
    },
    // 关闭国际运单弹窗
    domesticWaybillSwitch(e) {
      this.isOpenDomesticWaybill = false
      if (e == '1') {
        this.getList()
      }
    },
    // 切换选项卡
    tabsClick(tab, event) {
      this.queryParams.statusList = tab.name
      if (this.tabsValue == 'all') {
        this.loading = false
        this.queryParams.statusList = undefined
        this.sellerOrderList = []
      } else {
        this.getList()
      }
    },
    // 查看订单日志
    getOrderLog(row) {
      this.orderId = row.orderId
      this.isOpenOrderLog = true
    },
    // 关闭订单日志
    closeOrderLogModal(e) {
      this.isOpenOrderLog = e
    },
    // 菜鸟声明发货
    declarationShipment(row) {
      this.$confirm('是否确定执行声明发货操作？', '提示').then(() => {
        let data = {
          orderId: row.orderId
        }
        sellerShipmentForCaiNiao(data).then(res => {
          this.$message.success(res.msg)
          // this.isOpenNoodleList = false
          this.getList()
        })
      })
    },
    // SKU入库
    skuWarehouse(row) {
      this.$confirm('是否入库该订单？', '提示').then(() => {
        oldOrderSkuWarehousing({
          orderId: row.orderId
        }).then(res => {
          this.getList()
        })
      })
    },
    // 仓储发货
    warehouseShipping(row) {
      this.$prompt('请输入库存编码', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /([^\s])/,
        inputErrorMessage: '库存编码不能为空'
      }).then(({value}) => {
        let childOrderIds = [], skuCodes = [], dataList = [];
        this.sellerOrderList.forEach((item, index) => {
          if (item.orderId == row.orderId) {
            // if (item.sellerChildOrderList.length > 1) {
            let childOrdrList = item.sellerChildOrderList;
            childOrdrList.forEach((childItem, childIndex) => {
              dataList.push({
                orderId: row.orderId,
                childOrderId: childItem.childOrderId,
                skuCode: childItem.skuCode,
                trackingNumber: value
              })
              // childOrderIds.push(childItem.childOrderId)
              // skuCodes.push(childItem.skuCode)
            })
            // } else {
            // dataList.push({
            //   orderId: row.orderId,
            //   childOrderId: childItem.childOrderId,
            //   skuCode: childItem.skuCode,
            //   trackingNumber: value
            // })
            // childOrderIds.push(item.sellerChildOrderList[0].childOrderId)
            // skuCodes.push(item.sellerChildOrderList[0].skuCode)
            // }
          }
        })
        // let data = {
        //   orderId: row.orderId,
        //   childOrderId: childOrderIds.toString(),
        //   skuCode: skuCodes.toString(),
        //   trackingNumber: value
        // }
        getWarehouseProBySkuCode(dataList).then(res => {
          this.$message.success(res.msg)
          this.getList()
        })
      })
    },
    // 打开转仓储弹窗
    transferStorage(row) {
      this.isTransfer = true;
      this.transferForm.childOrderId = row.id;
      this.transferForm.type = '0';
    },
    // 转仓储
    confirmTransfer() {
      this.$refs["transferRef"].validate(valid => {
        if (valid) {
          addWarehousInfo(this.transferForm).then(response => {
            this.$message({
              type: 'success',
              message: response.msg
            })
            this.isTransfer = false;
            this.getList();
          }).finally(() => {
            this.isTransfer = false;
          })
        }
      })
    },
    // 补货
    supplementGoods() {
      let data = {
        "skuCode": "",
        "skuName": "",
        "status": "",
        "number": "",
        "cnTrackingNo": "",
        "proof": "",
        "childOrderId": "",
        "warehouseId": "",
        "arrivalTime": ""
      }
      warehouseProReplenish(data).then(res => {

      })
    },
    chooseOrder(row, status) {
      this.changeOrderStatus(row, status) //修改订单状态

    },

    // 修改订单状态
    changeOrderStatus(row, status) {
      // this.chooseOrder()
      // console.log('status', row, status)
      this.orderId = row.orderId
      let statusText = this.orderStatusData[status]
      this.$confirm('是否确定执行' + statusText + '操作?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let cutoffOrderData = {
          orderId: row.orderId
        }
        if (status == '502') { //同意
          cutOrderSuccess(cutoffOrderData).then(res => {
            this.$message({
              type: 'success',
              message: res.msg
            })
            this.getList() // 修改完状态后再次获取订单列表
          })
        } else {
          let data = {
            id: row && row.length > 0 ? row : row.id,
            erpInnerOrderStatus: status
          }
          alterInnerStatus(data).then(res => {
            this.$message({
              type: 'success',
              message: res.msg
            })
            this.getList() // 修改完状态后再次获取订单列表
          })
        }
      })
    },
    // 订单驳回
    orderReject(row) {
      this.$prompt('请输入驳回原因', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /([^\s])/,
        inputErrorMessage: '驳回原因必填'
      }).then(({value}) => {
        let data = {
          orderId: row.orderId,
          remark: value
        }
        reviewFailed(data).then(res => {
          this.$message.success(res.msg);
          this.getList();
        })
      })
    },
    // 拒绝截单
    orderRefuse(row) {
      this.$prompt('请输入拒绝原因', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /([^\s])/,
        inputErrorMessage: '拒绝原因必填'
      }).then(({value}) => {
        let data = {
          orderId: row.orderId,
          remark: value
        }
        cutOrderFail(data).then(res => {
          this.$message.success(res.msg);
          this.getList() // 修改完状态后再次获取订单列表
        })
      })
    },
    // 同意截单
    agreeCutOrder(row) {
      this.$confirm('请选择同意截单后操作', '提示', {
        confirmButtonText: "退货",
        cancelButtonText: "仓储",
        // center: true
      }).then(() => {
        // 退货
        this.$confirm("是否确定退货？", '提示').then(() => {
          let data = {
            orderId: row.orderId
          }
          cutOrderGoods(data).then(res => {
            this.$message.success(res.msg)
            this.getList()
          })
        })
      }).catch(() => {
        // 仓储
        this.openTransferWarehouse(row)
      })
    },
    // 打开仓储弹窗
    openTransferWarehouse(row) {
      querySendGoodsInfoList({orderId: row.orderId}).then(res => {
        this.isOpenTransferWarehouse = true
        this.sendGoodsInfoList = []
        this.orderId = row.orderId
        this.childOrderId = row.childOrderId
        let data = res.data
        if (data && data.length > 0) {
          let list = data
          for (let i = 0; i < list.length; i++) {
            this.sendGoodsInfoList.push({
              trackingNo: list[i].trackingNo,
              arrivalTime: formatDate(list[i].arrivalTime),
              childOrderId: list[i].childOrderId,
              orderId: list[i].orderId,
            })
          }
        } else {
          let list = row.sellerChildOrderList
          for (let i = 0; i < list.length; i++) {
            this.sendGoodsInfoList.push({
              trackingNo: '',
              arrivalTime: '',
              childOrderId: list[i].childOrderId,
              orderId: list[i].orderId,
            })
          }
        }
      });
    },
    // 关闭仓储弹窗
    closeTransferWarehouse(e) {
      this.isOpenTransferWarehouse = e
      this.getList()
    },
    // 订单详情弹窗开关
    orderDetailSwitch(e) {
      this.isOpenOrderDetail = e
    },
    /** 查询卖家订单列表 */
    getList() {
      // if (this.tabsValue == 'all') {
      //   this.loading = false
      //   this.queryParams.statusList = undefined
      //   this.sellerOrderList = []
      // } else {
      this.loading = true
      this.queryParams.orderProcessFlag = undefined
      let orderProcessFlag = {
        "103": ['begin'],//待采购
        "105": ["cainiao"],//已采购
        "1061": ["cainiao"],//待同步国际运单
        "1071": ["cainiao"],//待发货
        "106": ["cainiao"],//待出库
        "113": ["error"],//异常订单
        // "107": ["myself"],//已发货
        // "108": ["offline"],//声明发货
        "501": ["cutoff"],//截单订单
        "701": ["problem"],//问题件
      }
      this.queryParams.orderProcessFlag = orderProcessFlag[this.tabsValue]

      // this.queryParams.statusList = undefined
      if (this.tabsValue == '501' || this.tabsValue == '701') {
        this.queryParams.statusList = undefined
      }
      if (this.tabsValue == '1061') {
        this.queryParams.statusList = ['1061', '1062']
      }
      if (this.tabsValue == '1071') {
        this.queryParams.statusList = ['1071', '1072', '1073', '1074']
      }
      if (this.tabsValue == '113') {
        this.queryParams.statusList = undefined
      }

      listSellerOrder(this.queryParams).then(response => {
        // console.log(response, '*****')
        let list = response.rows
        this.sellerOrderList = list
        for (let i = 0; i < list.length; i++) {
          this.sellerOrderList[i]['checkValue'] = false
          for (let j = 0; j < list[i].sellerChildOrderList.length; j++) {
            if (list[i].orderId == list[i].sellerChildOrderList[j].orderId) {
              this.sellerOrderList[i].sellerChildOrderList[j]['erpInnerOrderStatus'] = this.sellerOrderList[i].erpInnerOrderStatus
              this.sellerOrderList[i].sellerChildOrderList[j]['orderData'] = this.sellerOrderList[i]
              this.sellerOrderList[i].sellerChildOrderList[j].id = String(this.sellerOrderList[i].sellerChildOrderList[j].id)
            }
          }
        }
        // console.log('this.sellerOrderList', this.sellerOrderList)
        this.chooseOrderList = [] // 清空所选择的订单
        this.total = response.total
        this.loading = false
      })
      // }
    },
    // 取消按钮
    cancel() {
      this.isOpenOrderDetail = false
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 重置
    resetOrderLog() {
      this.resetForm('orderLogForm')
      this.handleOrderLog()
    },
    handleSelectionChange(val) {
      // this.multipleSelection = val;
    },
    tableRowClassName({row, rowIndex}) {
      // console.log('rowIndex == 1', rowIndex == 1)
      if (row.sellerOperatorLoginId == 'cn1078275103recae') {
        return 'warning-row';
      }

      // if (row.sellerChildOrderList && row.sellerChildOrderList.length > 0) {
      //   let length = row.sellerChildOrderList.length
      //   // console.log('rowIndex', rowIndex)
      //   return 'warning-row';
      // } else {
      //   return 'success-row';
      // }
      // return '';
    },
    // 全选
    selectAllCheckbox(selection) {
      this.chooseOrderList = []
      if (selection.length > 0) {
        this.checkValue = true
        selection.forEach((item, index) => {
          this.sellerOrderList[index].checkValue = true
          this.chooseOrderList.push(item.orderId)
        })
      } else {
        this.sellerOrderList.forEach((item, index) => {
          this.sellerOrderList[index].checkValue = false
        })
      }
    },
    // 选择单选框
    changeCheckbox(selection) {
      for (let i = 0; i < this.sellerOrderList.length; i++) {
        if (this.sellerOrderList[i].orderId == selection.orderId) {
          this.chooseOrderList.push(selection.orderId)
        }
      }
      this.isChooseOrder = !this.isChooseOrder
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    //查看订单详情
    openOrderDetail(row) {
      this.orderId = row.orderId
      this.isOpenOrderDetail = true
    },
    // 打开修改采购链接弹窗
    openProcurementLinkModal(row) {
      this.skuCode = row.skuCode
      this.isOpenProcurementLink = true
    },
    // 跳转个人产品库
    goPersonalProduct(row) {
      const params = {v1: row.collectProductId, v2: '0'};
      this.$tab.openPage("产品详情", './publicProductDetail', params)
    },
  }
}
</script>
<style>
.el-table .warning-row {
  background: #fff1ca;
}

.el-table .success-row {
  background: rgb(255, 255, 255);
}

.programme-box-item {
  margin-bottom: 20px;
  padding: 20px 30px;
  border: 1px solid #eeeeee;
}

.programme-box-item-title {
  font-size: 16px;
  line-height: 20px;
  font-weight: bold;
  margin: 10px 0 20px;
  display: block;
}

.programme-box-flex {
  display: flex;
  justify-content: center;
}

.demo-table-expand label {
  width: 100px;
  color: #99a9bf;
  padding: 0;
}

.el-form-item el-form-item--small {
  margin-bottom: 0;
}

.el-form--label-left .el-form-item__label {
  text-align: right;
}

.demo-table-expand .el-form-item {
  width: 16%;
  margin-bottom: 0;
  margin-right: 0;
}

.img-box {
  display: flex;
  align-items: flex-start;
}

.edit-box {
  display: flex;
  align-items: center;
  /*justify-content: space-between;*/
  margin-bottom: 20px;
}

.edit-box-name {
  width: 120px;
  text-align: right;
}

.edit-box input {
  display: block;
}

/*去掉number输入框的上下箭头*/
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

input[type="number"] {
  -moz-appearance: textfield;
}

/*解决输入中文后光标上移的问题*/
.el-input__inner {
  line-height: 1px !important;
}
</style>
